<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>课程名称：</label>
                                <input type="text" name="coName"/>
                            </li>
                            <li>
                                <label>课程售价：</label>
                                <input type="text" name="money"/>
                            </li>
                            <li>
                                <label>教师编码：</label>
                                <input type="text" name="teacherCode"/>
                            </li>
                            <li>
                                <label>类别编码：</label>
                                <input type="text" name="caCode"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:course:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:course:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:course:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:course:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:course:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:course:remove')}]];
        var prefix = ctx + "system/course";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                //单元格点击事件
                onClickCell: onClickCell,
                modalName: "课程",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'cId',
                    title: '课程ID',
                    visible: false
                },
                {
                    field: 'courseCode',
                    title: '课程编码'
                },
                {
                    field: 'coName',
                    title: '课程名称'
                },
                {
                    field: 'courseVideoUrl',
                    title: '课程视频',
                    align: 'center',
                    formatter: function (value, row, index) {

                        let videosrc = "";
                        $.ajax({
                            type: "POST",
                            url: "/system/advertising/show",
                            data: {"fileName": value},
                            async:false,
                            success: function (data) {
                                videosrc = data.url;
                            }
                        });
                        /*return '<img src="' + imgsrc + '" width="50" height="50">';*/

                        return '<video controls="controls" height="90px" width="90px"> ' +
                            '<source type="video/mp4" src="' + videosrc + '"/></video>';
                    }
                },
                {
                    field: 'money',
                    title: '课程售价'
                },
                {
                    field: 'people',
                    title: '观看人数'
                },
                {
                    field: 'teacherCode',
                    title: '教师编码'
                },
                {
                    field: 'caCode',
                    title: '类别编码'
                },
                {
                    field: 'coCode',
                    title: '评论编码'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.cId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.cId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function onClickCell(field, value, row, $element){
            let videosrc = "";
            $.ajax({
                type: "POST",
                url: "/system/advertising/show",
                data: {"fileName": value},
                async:false,
                success: function (data) {
                    videosrc = data.url;
                }
            });
            //因为只需要视频单元格弹出，所以加一个字段判定
            if(field == 'courseVideoUrl'){
                layer.open({
                    type: 1,
                    title: '视频预览',
                    closeBtn: 0,
                    offset: ['90px'],
                    skin: 'layui-layer-nobg', //没有背景色
                    shadeClose: true,
                    content: '<video controls="controls"> <source type="video/mp4" src="' + videosrc + '"/></video>'
                });
            }
        }

    </script>
</body>
</html>